<template>
    <HeaderCom>
        <template v-slot:left>
            <svg class="icon" @click="fanHui">
                <use xlink:href="#icon-houtui"></use>
            </svg>
        </template>
        <template v-slot:center>
            <div id="search">
                <svg class="icon">
                    <use xlink:href="#icon-sousuo"></use>
                </svg>
                <input type="text" placeholder="大家都在搜陶喆" v-model="souSuo" @focus="qingKong">
            </div>
        </template>
        <template v-slot:right>
            <span @click="add">搜索</span>
        </template>
    </HeaderCom>
</template>

<script>
    import HeaderCom from "../header/HeaderCom.vue";
    import {getBanner} from "@/api";
    export default {
        name: "SearchHeaderCom",
        components:{
            HeaderCom,
        },
        data(){
            return{
                souSuo:'',
                souSuoNeiRong:null
            }
        },
        methods:{
            add(){
                if(this.souSuo!=='')this.$store.dispatch('liShi',this.souSuo)
                getBanner(`/search/multimatch?keywords=${this.souSuo}`)
                    .then(response=>{
                        this.souSuoNeiRong=response.data.result
                        console.log(this.souSuoNeiRong)
                    })
                setTimeout(()=>{
                    this.$router.push({path:'/search-view-result',query:{souSuoNeiRong:JSON.stringify(this.souSuoNeiRong)}})
                },1000)

            },
            qingKong(){
                this.souSuo=''
            },
            fanHui(){
                history.go(-1)
            }
        }
    }
</script>

<style scoped>
    svg{
        width: 20px;
        height: 20px;
    }
    #search{
        height: 30px;
        border-radius: 15px;
        background: lightgrey;
        margin-top: 10px;
        line-height: 30px;
    }
    div>svg{
        vertical-align: middle;
        margin-left: 10px;
        margin-right: 10px;
    }
    input{
        border: 0;
        background: lightgrey;
        outline: none;
    }
</style>